package org.edu.modules.message.controller;

import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.edu.common.api.vo.Result;
import org.edu.common.system.query.QueryGenerator;
import org.edu.modules.message.entity.VeSiteSimple;
import org.edu.modules.message.service.IVeSiteSimpleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.edu.common.system.base.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.edu.common.aspect.annotation.AutoLog;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @Description: 单页面信息
 * @Author:
 * @Date:   2021-01-22
 * @Version: V1.0
 */
@Api(tags="单页面信息")
@RestController
@RequestMapping("/portal/veSiteSimple")
@Slf4j
@ApiSort(value = 60)
public class VeSiteSimpleController extends BaseController<VeSiteSimple, IVeSiteSimpleService> {
	@Autowired
	private IVeSiteSimpleService veSiteSimpleService;

	/**
	 * 获取单条信息
	 * @param veSiteSimple
	 * @param req
	 * @return
	 */
	@AutoLog(value = "单页面信息-获取单条信息")
	@ApiOperation(value="获取单条信息", notes="单页面信息-获取单条信息")
	@PostMapping(value = "/getOne")
	@ApiOperationSupport(order = 1)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "cateid", value = "栏目id", required = true),
	})
	public Result<?> getOne(@ApiIgnore VeSiteSimple veSiteSimple,
								   HttpServletRequest req) {
		QueryWrapper<VeSiteSimple> queryWrapper = QueryGenerator.initQueryWrapper(veSiteSimple, req.getParameterMap());
		VeSiteSimple veSiteSimple0 = veSiteSimpleService.getOne(queryWrapper);
		return Result.OK(veSiteSimple0);
	}

	/**
	* 通过id查询
	* @param id
	* @return
	*/
	@AutoLog(value = "单页面信息-通过id查询")
	@ApiOperation(value="通过id查询", notes="单页面信息-通过id查询")
	@PostMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		VeSiteSimple veSiteSimple = veSiteSimpleService.getById(id);
		if(veSiteSimple==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(veSiteSimple);
	}

	/**
	 * 新增信息
	 * @param veSiteSimple
	 * @return
	 */
	@AutoLog(value = "单页面信息-新增信息")
	@ApiOperation(value="新增信息", notes="单页面信息-新增信息")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody VeSiteSimple veSiteSimple) {
		veSiteSimpleService.save(veSiteSimple);
		return Result.OK("添加成功！");
	}

	/**
	 * 修改信息
	 * @param veSiteSimple
	 * @return
	 */
	@AutoLog(value = "单页面信息-修改信息")
	@ApiOperation(value="修改信息", notes="单页面信息-修改信息")
	@PostMapping(value = "/edit")
	public Result<?> edit(@RequestBody VeSiteSimple veSiteSimple) {
		veSiteSimpleService.updateById(veSiteSimple);
		return Result.OK("编辑成功!");
	}

	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@AutoLog(value = "单页面信息-通过id删除")
	@ApiOperation(value="通过id删除", notes="单页面信息-通过id删除")
	@PostMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		veSiteSimpleService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "单页面信息-批量删除")
	@ApiOperation(value="批量删除", notes="单页面信息-批量删除")
	@PostMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.veSiteSimpleService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

}
